package com.library.service;

import com.library.bean.Book;
import com.library.bean.PageInfo;
import com.library.dao.BookDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;

@Service
public class BookService {

    @Autowired
    private BookDao bookDao;

    public ArrayList<Book> findByCurrentPage(int currentPage) throws IOException {
        return bookDao.findByCurrentPage(currentPage);
    }

    public PageInfo<Book> findByPage(int currentPage) throws IOException {
        PageInfo<Book> pageInfo=bookDao.findByPage(currentPage);
        return pageInfo;
    }

    public Book getBookById(long bookId) {
        return bookDao.getBook(bookId);
    }

    public boolean addBook(Book book) {
        return bookDao.addBook(book)>0;
    }

    public boolean deleteBook(Long bookId) {
        return bookDao.deleteBook(bookId)>0;
    }

    public boolean editBook(Book book) {
        return bookDao.editBook(book)>0;
    }

    public boolean matchBook(String searchWord) throws IOException {
        return bookDao.matchBook(searchWord)>0;
    }

    public ArrayList<Book> qureyBook(String searchWord) {
        return bookDao.qureyBook(searchWord);
    }

    public boolean updatebooknum(Book book) {
        return bookDao.updateBooknum(book)>0;
    }

    public boolean returnbooknum(Book book) {
        return bookDao.returnBooknum(book)>0;
    }

    public ArrayList<Book> getAllBooks() {

        return bookDao.getAllBooks();
    }
}
